﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace ReadXml
{
    class GetXml
    {
        public List<List<double>> getXml(string url)
        {
            /***** 变量定义和初始化 *****/
            XmlDocument xml = new XmlDocument();
            xml.Load(url);
            XmlNode xn = xml.SelectSingleNode("RightHand");
            XmlNodeList xnl = xn.ChildNodes;
            List<double> kinectArrayX = new List<double>();
            List<double> kinectArrayY = new List<double>();
            List<double> kinectArrayZ = new List<double>(); //用了三个list泛型

            /***** 遍历FrameNum读取xml内容 *****/
            for (int i = 0; i < xnl.Count; i++ )
            {
                XmlNodeList xn0 = xnl[i].ChildNodes;  // 得到FrameNum节点的所有子节点
                kinectArrayX.Add(double.Parse(xn0.Item(2).InnerText));
                kinectArrayY.Add(double.Parse(xn0.Item(3).InnerText));
                kinectArrayZ.Add(double.Parse(xn0.Item(4).InnerText));
                //Console.WriteLine(" X: " + kinectArrayX[i] + " Y: " + kinectArrayY[i] + " Z: " + kinectArrayZ[i]);
            }
            double[] min = new double[3] { kinectArrayX.Min(), kinectArrayY.Min(), kinectArrayZ.Min() };
            double[] max = new double[3] { kinectArrayX.Max(), kinectArrayY.Max(), kinectArrayZ.Max() };

            /***** 遍历数组，进行归一化 *****/
            for (int i = 0; i < kinectArrayX.Count; i++)
            {
                kinectArrayX[i] = (kinectArrayX[i] - min[0]) / (max[0]-min[0]); //normalization
                kinectArrayY[i] = (kinectArrayY[i] - min[1]) / (max[1] - min[1]);
                kinectArrayZ[i] = (kinectArrayZ[i] - min[2]) / (max[2] - min[2]);
                //Console.WriteLine(" X: " + kinectArrayX[i] + " Y: " + kinectArrayY[i] + " Z: " + kinectArrayZ[i]);
            }

            /***** 返回二维list *****/  
            List<List<double>> kinectArray = new List<List<double>>();
            kinectArray.Add(kinectArrayX);
            kinectArray.Add(kinectArrayY);
            kinectArray.Add(kinectArrayZ);
            //Console.WriteLine(kinectArray[0][0]);
            return kinectArray;
        }
    }
}
